angular.module('inventory.controllers', ['inventory.services'])

.controller('InventoryCtrl', function($scope,InventoryService) {
	InventoryService.overview($scope,{'qty': {$lt: 3}},function(data){
		$scope.inventoryStatus = data;
	});

	InventoryService.caclValue($scope,{},function(data){
		$scope.totalValue = data;
	});


})
// 所有库存
.controller('InventoryAllCtrl', function($scope,InventoryService) {
	$scope.title = '全部';
	InventoryService.list($scope,{},function(list,subtotal){
		$scope.inventoryList=list;
		$scope.subtotal=subtotal;
	});
	$scope.toggleItem = function(item) {
		if ($scope.isItemShown(item)) {
			$scope.shownItem = null;
		} else {
		 	$scope.shownItem = item;
		}
	};
	$scope.isItemShown = function(item) {
		return $scope.shownItem === item;
	};

})
// 库存警报
.controller('InventoryAlarmCtrl', function($scope,InventoryService) {
	$scope.title = '量低';
	$scope.showFilter =false;
	InventoryService.list($scope,{'qty': {$lt: 3}},function(list,subtotal){
		$scope.inventoryList=list;
		$scope.subtotal=subtotal;
	});

	$scope.toggleItem = function(item) {
		if ($scope.isItemShown(item)) {
			$scope.shownItem = null;
		} else {
		 	$scope.shownItem = item;
		}
	};
	$scope.isItemShown = function(item) {
		return $scope.shownItem === item;
	};
})
// 品牌列表
.controller('BrandListCtrl', function($scope,InventoryService) {
	InventoryService.getBrandList($scope,{},function(list){
		$scope.brands=list;
	});
})
//品牌库存
.controller('BrandInventoryCtrl', function($scope,$stateParams,InventoryService) {
	InventoryService.list($scope,{'brand.name':$stateParams.brandName},function(data,total){
		$scope.inventoryList = data;
		$scope.subtotal = total;
	});

	$scope.toggleItem = function(item) {
		if ($scope.isItemShown(item)) {
			$scope.shownItem = null;
		} else {
		 	$scope.shownItem = item;
		}
	};
	$scope.isItemShown = function(item) {
		return $scope.shownItem === item;
	};
})
// 库存详情
.controller('InventoryDetailCtrl', function($scope,$stateParams,InventoryService) {
		InventoryService.getDetailById($scope,{'_id':$stateParams._id},function(){});
});
